/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.pitkley.jocabulary;

import java.io.*;
import java.util.*;

/**
 *
 * @author pit
 */
public class Language {

    private ArrayList<Set> sets = new ArrayList<Set>();
    private ArrayList<Unit> units = new ArrayList<Unit>();
    private String name;
    private String cleanName;

    Language(String pName, String pCleanName) {
        name = pName;
        cleanName = pCleanName;
    }

    public void addUnit(String pUnitName, String pCleanName, int pOnlineRevision, String pSetName) throws IOException {
        Unit u = new Unit(pUnitName, pCleanName, pOnlineRevision);
        units.add(u);
        if(pSetName != null) {
            getSet(pSetName).addUnit(u);
        }
    }

    public ArrayList<Unit> getUnits() {
        return units;
    }

    public Unit getUnit(int index) {
        return units.get(index);
    }

    public int getUnitCount() {
        return units.size();
    }

    public void addSet(String pName, String pCleanName) {
        sets.add(new Set(pName, pCleanName));
    }

    public ArrayList<Set> getSets() {
        return sets;
    }
    
    public Set getSet(String pName) {
        for (Set s : sets) {
            if (s.getName().equals(pName)) {
                return s;
            } else {
                continue;
            }
        }
        
        return null;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return this.cleanName;
    }

    public String getCleanName() {
        return cleanName;
    }
}
